home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-12-04 | 7.3 KB | 385 lines | [TEXT/KAHL] |
- //• RadarScope.c
-
-
- #include <math.h>
-
- #define over qd.screenBits.bounds.right
- #define down qd.screenBits.bounds.bottom
-
- #define drawWindow 2
-
- typedef struct Info
- {
- RgnHandle clip;
- Rect rect;
- short h;
- short v;
- } Info;
-
- Info stuff[20];
-
- typedef struct
- {
- WindowRecord windRec;
- short windtype;
- Boolean drawnIn;
- } MyWindRecord, *MyWindPeek;
-
- MenuHandle appleMenu, fileMenu, editMenu, widthMenu;
-
- enum {
- appleID = 1,
- fileID,
- editID,
- widthID
- };
- enum {
- openItem = 1,
- closeItem,
- quitItem = 4
- };
- Point centre, circle[360], deltaPt, lastPt, whereLast;
-
- short bottom, lasti, radius, width, height, right, left, bottom, top;
-
- Rect globWind, ourRect;
- EventRecord theEvent;
- RgnHandle tempRgnHandle;
- Str255 strangs[20];
- WindowPtr shell_window;
- short windowType;
-
- void InitRadar (Rect *drawArea, short ID);
- void DrawRadar (short ID);
- void Action (void);
- void SetUp (short ID);
- void TakeDown (short ID);
- void StowInfo (Rect *tempRect, short ID);
- void SetUpWindow (void);
- Boolean DetermineDrawnInFlag (WindowPtr theWindow);
- void UpdateDrawWindow (WindowPtr theWindow);
- void DoSomeUpdateStuff (void);
- void HandleUpdate (void);
- short DetermineWindowType (WindowPtr theWindow);
- void InitManagers (short numMasters);
- short MainEvent (void);
- void DoAbout (void);
- void SetUpMenus (void);
- void DoKeyDownStuff (void);
- short HandleMenu (long mSelect);
- void main (void);
-
- void InitRadar (Rect *drawArea, short ID)
- {
- short i;
- double sinner, cosinner, thetaStep, theta;
-
- //• Our rectangle is at the drawArea, which is tempRect, which
- //• is the one 4 pixels in, in the window.
- ourRect = *drawArea;
-
- //• So, width is 192 pixels, and so is height.
- width = ourRect.right;
- height = ourRect.bottom;
-
- //• This makes radius half that, or 96
- radius = width / 2;
- centre.h = radius;
- centre.v = radius;
- thetaStep = (2 * 3.14159) / 360;
- theta = 0;
- for (i = 0; i < 360; i++)
- {
- circle[i].h = radius * cos (theta) + radius;
- circle[i].v = radius * sin (theta) + radius;
- theta += thetaStep;
- }
- lasti = 0;
- }
-
- void DrawRadar (short ID)
- {
- FillOval (&ourRect, black);
- MoveTo (centre.h, centre.v);
- PenMode (srcXor);
- LineTo (circle[lasti].h, circle[lasti].v);
- lasti = (++lasti % 360);
- PenPat (black);
- }
-
- void Action (void)
- {
- SetUp (1);
- DrawRadar (1);
- TakeDown (1);
- }
-
- void SetUp (short ID)
- {
- SetClip (stuff[ID].clip);
- SetOrigin (stuff[ID].h, stuff[ID].v);
- }
-
- void TakeDown (short ID)
- {
- SetOrigin (0, 0);
- }
-
- void StowInfo (Rect *tempRect, short ID)
- {
- RgnHandle tempRgn;
-
- stuff[ID].rect = *tempRect;
- stuff[ID].h = - tempRect->left;
- stuff[ID].v = - tempRect->top;
-
- InsetRect (&stuff[ID].rect, -1, -1);
- tempRgn = NewRgn ();
- OffsetRect (tempRect, stuff[ID].h, stuff[ID].v);
- RectRgn (tempRgn, tempRect);
- stuff[ID].clip = tempRgn;
- }
-
- void SetUpWindow (void)
- {
- Rect tempRect, frameRect, ovalRect;
- RgnHandle tempRgn;
-
- //• Since QuickDraw has the port set globally (default),
- //• we get the screen size off right and bottom, and
- //• backtrack off it. The below results in a 200x200
- //• window centered on the screen.
- SetRect (&globWind, over / 2 - 100,
- down / 2 - 100,
- over / 2 + 100,
- down / 2 + 100);
-
- shell_window = NewWindow (0L, &globWind, "\pKen's Shell", true,
- plainDBox, (WindowPtr) -1L, true, 0);
-
- //• Now we've said the WindowPtr points to a window in the
- //• rectangle we set off the screen size. So we localize our
- //• coordinates to that window by saying IT is the port that
- //• QuickDraw will draw in.
- SetPort (shell_window);
-
- //• Now we set a rectangle inside that local port. Since it's
- //• a 200 pixel square window, it's 2 pixels in on all sides.
- SetRect (&frameRect, 2, 2, 198, 198);
-
- //• Now we frame it.
- FrameRect (&frameRect);
-
- //• Now we set another one 4 pixels in, to show our stuff in.
- SetRect (&tempRect, 4, 4, 196, 196);
-
- StowInfo (&tempRect, 1);
- InitRadar (&tempRect, 1);
-
- stuff[0].clip = NewRgn ();
- GetClip (stuff[0].clip);
- }
-
- void DoSomeUpdateStuff (void)
- {
- short i;
- SetClip (stuff[0].clip);
- FrameRect (&stuff[i].rect);
- }
-
- void InitManagers (short numMasters)
- {
- short i;
- InitGraf (&thePort);
- InitFonts ();
- InitWindows ();
- InitMenus ();
- TEInit ();
- InitDialogs (((void *) 0));
- for (i = 0; i < 5; i++)
- {
- MoreMasters ();
- }
- FlushEvents (everyEvent, 0);
- InitCursor ();
- }
-
- short MainEvent ()
- {
- WindowPtr whichWindow;
- Rect r;
- SystemTask ();
- if (GetNextEvent (everyEvent, &theEvent))
- {
- switch (theEvent.what)
- {
- case mouseDown:
- switch (FindWindow (theEvent.where, &whichWindow))
- {
- case inDesk:
- break;
-
- case inMenuBar:
- return (HandleMenu (MenuSelect (theEvent.where)));
- break;
-
- case inGoAway:
- break;
-
- case inSysWindow:
- break;
-
- case inContent:
- break;
-
- case inDrag:
- SetRect (&r, 0, 0, 5000, 5000);
- DragWindow (whichWindow, theEvent.where, &r);
- break;
- }
- break;
-
- case keyDown:
- case autoKey:
- DoKeyDownStuff ();
- break;
-
- case activateEvt:
- break;
-
- case updateEvt:
- BeginUpdate (shell_window);
- // HandleUpdate ();
- DoSomeUpdateStuff ();
- EndUpdate (shell_window);
- break;
-
- default:;
- }
- }
- Action ();
- HiliteMenu (0);
- return (1);
- }
-
- void DoAbout ()
- {
- Boolean done;
- short theItem;
- DialogPtr AboutPtr;
- short itemType;
- Handle item;
- Rect box;
- done = 0;
- AboutPtr = GetNewDialog (128,0L, (WindowPtr)-1);
- while (!done)
- {
- ModalDialog (0L,&theItem);
- switch (theItem)
- {
- case OK:
- done = 1;
- break;
-
- case Cancel:
- done = 1;
- break;
- }
- }
- DisposDialog (AboutPtr);
- }
-
- void SetUpMenus (void)
- {
- InsertMenu (appleMenu = NewMenu (appleID, "\p\024"), 0);
- InsertMenu (fileMenu = NewMenu (fileID, "\pFile"), 0);
- InsertMenu (editMenu = NewMenu (editID, "\pEdit"), 0);
- InsertMenu (widthMenu = NewMenu (widthID, "\pBlips"), 0);
- DrawMenuBar ();
- AddResMenu (appleMenu, 'DRVR');
- AppendMenu (fileMenu, "\pOpen/O;Close/W; (-;Quit/Q");
- AppendMenu (editMenu, "\pUndo/Z; (-;Cut/X;Copy/C;Paste/V;Clear");
- AppendMenu (widthMenu, "\p0/0;1/1;2/2;3/3;4/4;5/5;6/6;7/7;8/8;9/9");
- }
-
- void DoKeyDownStuff ()
- {
- short chr;
- long menuChoice;
-
- chr = theEvent.message & charCodeMask;
-
- if ((theEvent.modifiers & cmdKey) != 0)
- {
- if (theEvent.what != autoKey)
- {
- menuChoice = MenuKey (chr);
- HandleMenu (menuChoice);
- }
- }
- }
-
- short HandleMenu (long mSelect)
- {
- short menuID = HiWord (mSelect);
- short menuItem = LoWord (mSelect);
- Str255 name;
- GrafPtr savePort;
- WindowPeek frontWindow;
- switch (menuID)
- {
- case appleID:
- GetPort (&savePort);
- GetItem (appleMenu, menuItem, name);
- OpenDeskAcc (name);
- SetPort (savePort);
- break;
-
- case fileID:
- switch (menuItem)
- {
- case openItem:
- ShowWindow (shell_window);
- SelectWindow (shell_window);
- break;
-
- case closeItem:
- if ((frontWindow = (WindowPeek) FrontWindow ()) == 0L)
- break;
-
- if (frontWindow->windowKind < 0)
- CloseDeskAcc (frontWindow->windowKind);
- else
- if (frontWindow = (WindowPeek) shell_window)
- HideWindow (shell_window);
- break;
-
- case quitItem:
- ExitToShell ();
- break;
- }
- break;
-
- case editID:
- if (!SystemEdit (menuItem-1))
- SysBeep (5);
- break;
-
- case widthID:
- CheckItem (widthMenu, width, false);
- width = menuItem;
- InvalRect (&shell_window->portRect);
- break;
- }
- }
-
- void main ()
- {
- InitManagers (5);
- SetUpMenus ();
- SetUpWindow ();
- for (;;)
- MainEvent ();
- }
-
-